package com.msw.design.observer;

import java.lang.reflect.Method;

/**
 * Created by hadoop on 17-7-4.
 */
public class JLineConsole {
    public static void main(String[] args) throws Exception {
        Class consoleC = Class.forName("jline.ConsoleReader");
//        Class completorC =
//                Class.forName("org.apache.zookeeper.JLineZNodeCompletor");

        System.out.println("JLine support is enabled");

        Object console =
                consoleC.getConstructor().newInstance();

//        Object completor =
//                completorC.getConstructor(ZooKeeper.class).newInstance(zk);
//        Method addCompletor = consoleC.getMethod("addCompletor",
//                Class.forName("jline.Completor"));
//        addCompletor.invoke(console, completor);

        String line;
        Method readLine = consoleC.getMethod("readLine", String.class);
        while ((line = (String)readLine.invoke(console, "cmd")) != null) {
            executeLine(line);
        }
    }


    private static void executeLine(String line) {
        System.out.println(line);
    }

}
